package com.relatev.minecraft.UWantRestart.Sponge;

import com.relatev.minecraft.UWantRestart.RestartCondition;
import java.util.concurrent.TimeUnit;
import org.spongepowered.api.Sponge;

public class SPFunctionModule implements Runnable {

    private static SPFunctionModule Instance;
    private static String KickMessage;

    public static void init() {
        Instance = new SPFunctionModule();
        Sponge.getScheduler().createTaskBuilder().interval(60, TimeUnit.SECONDS).execute(Instance).submit(UWantRestartSP.MainPlugin);
        KickMessage = SPConfigManager.RootNode.getNode("KickMessage").getString();
        for (RestartCondition rc : SPConfigManager.Conditions) {
            if (rc.meetCondition(Sponge.getServer().getOnlinePlayers().size())) {
                rc.StartIgnore = true;
            }
        }
    }

    @Override
    public void run() {
        for (RestartCondition rc : SPConfigManager.Conditions) {
            if (rc.meetCondition(Sponge.getServer().getOnlinePlayers().size())) {
                SPRestartTasker.restart(KickMessage, 0);
            }else{
                rc.StartIgnore = false;
            }
        }
    }
}
